<template>
  <a-modal title-align="start" title="确认收样" :mask-closable="false" v-model:visible="showvisible" @cancel="showvisible = false" :width="400">
    <div>您必须确认确实已经收到了实物样品</div>
    <a-space>
      <div class="required"> 实际收到样品时间 </div>
      <div class="mt10">
        <a-date-picker v-model="time" value-format="timestamp" />
      </div>
    </a-space>
    <template #footer class="modal-footer">
      <a-button @click="showvisible = false">取消</a-button>
      <a-button type="primary" :loading="loading" @click="submit">确定</a-button>
    </template>
  </a-modal>
</template>

<script lang="ts" setup>
  import { defineComponent, ref, computed, onMounted } from 'vue'
  import { confirmReceiveSample } from '@/api/task'
  import { Message } from '@arco-design/web-vue'
  let props = defineProps(['modelValue', 'ids'])
  let emits = defineEmits(['save', 'update:modelValue'])
  let showvisible = computed({
    get() {
      return props.modelValue
    },
    set(val) {
      emits('update:modelValue', val)
    },
  })
  let loading = ref(false)
  let time = ref(0)
  const submit = async () => {
    if (!time.value) return Message.error('请选择实际收到样品时间')
    let params = {
      gmtReceive: time.value,
      idList: props.ids,
    }
    loading.value = true
    const res: any = await confirmReceiveSample(params)
    if (res) {
      Message.success('收样成功')
      emits('save')
      showvisible.value = false
    }
    loading.value = false
  }

  onMounted(() => {
    time.value = new Date().getTime()
  })
</script>

<style lang="less" scoped></style>
